knitr::opts_chunk$set(echo = TRUE)
library(devtools)
## Loading required package: usethis
library(rprojroot)
load_all()
## ℹ Loading DSPWorkflow
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
## Loading required package: Biobase
## Loading required package: BiocGenerics
## 
## Attaching package: 'BiocGenerics'
## The following objects are masked from 'package:stats':
## 
##     IQR, mad, sd, var, xtabs
## The following objects are masked from 'package:base':
## 
##     anyDuplicated, append, as.data.frame, basename, cbind, colnames,
##     dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,
##     grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,
##     order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
##     rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,
##     union, unique, unsplit, which.max, which.min
## Welcome to Bioconductor
## 
##     Vignettes contain introductory material; view with
##     'browseVignettes()'. To cite Bioconductor, see
##     'citation("Biobase")', and for packages 'citation("pkgname")'.
## Loading required package: cowplot
## Loading required package: dplyr
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:Biobase':
## 
##     combine
## The following objects are masked from 'package:BiocGenerics':
## 
##     combine, intersect, setdiff, union
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## Loading required package: GeomxTools
## Loading required package: NanoStringNCTools
## Loading required package: S4Vectors
## Loading required package: stats4
## 
## Attaching package: 'S4Vectors'
## The following objects are masked from 'package:dplyr':
## 
##     first, rename
## The following objects are masked from 'package:base':
## 
##     expand.grid, I, unname
## Loading required package: ggplot2
## 
## Attaching package: 'NanoStringNCTools'
## The following object is masked from 'package:dplyr':
## 
##     groups
## Loading required package: ggforce
## Loading required package: gridExtra
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
## The following object is masked from 'package:Biobase':
## 
##     combine
## The following object is masked from 'package:BiocGenerics':
## 
##     combine
## Loading required package: grid
## Loading required package: gtable
## Loading required package: knitr
## Loading required package: patchwork
## 
## Attaching package: 'patchwork'
## The following object is masked from 'package:cowplot':
## 
##     align_plots
## Loading required package: reshape2
## Loading required package: Rtsne
## Loading required package: scales
## Loading required package: SpatialDecon
## Loading required package: tibble
## Loading required package: tidyr
## 
## Attaching package: 'tidyr'
## The following object is masked from 'package:reshape2':
## 
##     smiths
## The following object is masked from 'package:S4Vectors':
## 
##     expand
## Loading required package: umap
## Loading required package: magrittr
## 
## Attaching package: 'magrittr'
## The following object is masked from 'package:tidyr':
## 
##     extract
## Loading required package: ComplexHeatmap
## ========================================
## ComplexHeatmap version 2.10.0
## Bioconductor page: http://bioconductor.org/packages/ComplexHeatmap/
## Github page: https://github.com/jokergoo/ComplexHeatmap
## Documentation: http://jokergoo.github.io/ComplexHeatmap-reference
## 
## If you use it in published research, please cite:
## Gu, Z. Complex heatmaps reveal patterns and correlations in multidimensional 
##   genomic data. Bioinformatics 2016.
## 
## The new InteractiveComplexHeatmap package can directly export static 
## complex heatmaps into an interactive Shiny app with zero effort. Have a try!
## 
## This message can be suppressed by:
##   suppressPackageStartupMessages(library(ComplexHeatmap))
## ========================================
root <- rprojroot::find_package_root_file()

knitr::opts_chunk$set(fig.width=12, fig.height=8, out.width = '100%') 
knitr::opts_knit$set(root.dir = root)

R Markdown

This runs the DSPworkflow package to completion using the Mouse Thymus Dataset:

1. Study Design:

  # Set paths for downloading dcc files
  downloads.path <- test_path("fixtures/Mouse_Thymus/downloaded/")
  tar.file.name <- "thymus_dccs.tar.gz"
  full.tar.path <- paste0(downloads.path,tar.file.name)
  
  # Check if dcc files were previously downloaded
  if (!file.exists(full.tar.path)) {
    
    # Download dcc files and place in data folder
    data.url <- "http://hpc.nih.gov/~CCBR/DSPWorkflow/thymus_dccs.tar.gz"
    download.file(data.url, full.tar.path)
    untar(full.tar.path, exdir = downloads.path)
  }
  
  dcc.files <- dir(
    file.path(
      downloads.path,
      "dccs"
    ),
    pattern = ".dcc$",
    full.names = TRUE,
    recursive = TRUE
  )
    
  pkc.files <-
    test_path("fixtures/Mouse_Thymus/Mm_R_NGS_WTA_v1.0.pkc")
  pheno.data.file <-
    test_path("fixtures/Mouse_Thymus/Thymus_Annotation_updated_3.xlsx")
  
  sdesign.list <- studyDesign(dcc.files = dcc.files, 
                                pkc.files = pkc.files,
                                pheno.data.file = pheno.data.file,
                                pheno.data.sheet = "Annotation",
                                pheno.data.dcc.col.name = "Sample_ID",
                                protocol.data.col.names = c("aoi", "roi"),
                                experiment.data.col.names = c("panel"),
                                slide.name.col = "slide name", 
                                class.col = "class", 
                                region.col = "region", 
                                segment.col = "segment",
                                area.col = "area",
                                nuclei.col = "nuclei")
  
  # For creating fixture RDS
  create.rds <- TRUE
  if(create.rds) {
    study.design.mouse.thymus <- sdesign.list$object
    saveRDS(study.design.mouse.thymus, file = "tests/testthat/fixtures/Mouse_Thymus/studyDesignMouseThymus.RDS")
  }
  
  print(sdesign.list$sankey.plot)

  print("Created GeoMx Object\n\n")
## [1] "Created GeoMx Object\n\n"
  pData(sdesign.list$object)[,c("slide_name","class","segment")]  
##                             slide_name   class segment
## DSP-1001660007393-A-A02.dcc  1057/1059  Thymus    B220
## DSP-1001660007393-A-A03.dcc  1057/1059  Thymus   PanCK
## DSP-1001660007393-A-A04.dcc  1057/1059  Thymus     CD3
## DSP-1001660007393-A-A05.dcc  1057/1059  Thymus   PanCK
## DSP-1001660007393-A-A06.dcc  1057/1059  Thymus     CD3
## DSP-1001660007393-A-A07.dcc  1057/1059  Thymus   PanCK
## DSP-1001660007393-A-A08.dcc  1057/1059  Thymus     CD3
## DSP-1001660007393-A-A09.dcc  1057/1059  Thymus   PanCK
## DSP-1001660007393-A-A10.dcc  1057/1059  Thymus     CD3
## DSP-1001660007393-A-A11.dcc  1057/1059  Thymus   PanCK
## DSP-1001660007393-A-A12.dcc  1057/1059  Thymus     CD3
## DSP-1001660007393-A-B01.dcc  1057/1059  Thymus   PanCK
## DSP-1001660007393-A-B02.dcc  1057/1059  Thymus     CD3
## DSP-1001660007393-A-B03.dcc  1057/1059  Thymus   PanCK
## DSP-1001660007393-A-B04.dcc  1057/1059  Thymus     CD3
## DSP-1001660007393-A-B05.dcc  1057/1059  Thymus   PanCK
## DSP-1001660007393-A-B06.dcc  1057/1059  Thymus     CD3
## DSP-1001660007393-A-B07.dcc  1057/1059  Thymus    B220
## DSP-1001660007393-A-B08.dcc  1057/1059  Thymus    B220
## DSP-1001660007393-A-B09.dcc  1057/1059  Thymus    B220
## DSP-1001660007393-A-B10.dcc  1057/1059  Thymus   PanCK
## DSP-1001660007393-A-B11.dcc  1057/1059  Thymus     CD3
## DSP-1001660007393-A-B12.dcc  1057/1059  Thymus   PanCK
## DSP-1001660007393-A-C01.dcc  1057/1059  Thymus     CD3
## DSP-1001660007393-A-C02.dcc  1057/1059  Thymus   PanCK
## DSP-1001660007393-A-C03.dcc  1057/1059  Thymus     CD3
## DSP-1001660007393-A-C04.dcc  1057/1059  Thymus   PanCK
## DSP-1001660007393-A-C05.dcc  1057/1059  Thymus     CD3
## DSP-1001660007393-A-C06.dcc  1072/1043  Thymus    B220
## DSP-1001660007393-A-C07.dcc  1072/1043  Thymus    B220
## DSP-1001660007393-A-C08.dcc  1072/1043  Thymus    B220
## DSP-1001660007393-A-C09.dcc  1072/1043  Thymus     CD3
## DSP-1001660007393-A-C10.dcc  1072/1043  Thymus   PanCK
## DSP-1001660007393-A-C11.dcc  1072/1043  Thymus     CD3
## DSP-1001660007393-A-C12.dcc  1072/1043  Thymus   PanCK
## DSP-1001660007393-A-D01.dcc  1072/1043  Thymus     CD3
## DSP-1001660007393-A-D02.dcc  1072/1043  Thymus   PanCK
## DSP-1001660007393-A-D03.dcc  1072/1043  Thymus     CD3
## DSP-1001660007393-A-D04.dcc  1072/1043  Thymus   PanCK
## DSP-1001660007393-A-D05.dcc  1072/1043  Thymus     CD3
## DSP-1001660007393-A-D06.dcc  1072/1043  Thymus   PanCK
## DSP-1001660007393-A-D07.dcc  1072/1043  Thymus     CD3
## DSP-1001660007393-A-D08.dcc  1072/1043  Thymus   PanCK
## DSP-1001660007393-A-D09.dcc  1072/1043  Thymus     CD3
## DSP-1001660007393-A-D10.dcc  1072/1043  Thymus   PanCK
## DSP-1001660007393-A-D11.dcc  1072/1043  Thymus     CD3
## DSP-1001660007393-A-D12.dcc  1072/1043  Thymus   PanCK
## DSP-1001660007393-A-E01.dcc  1072/1043  Thymus     CD3
## DSP-1001660007393-A-E02.dcc  1072/1043  Thymus   PanCK
## DSP-1001660007393-A-E03.dcc  1072/1043  Thymus    B220
## DSP-1001660007393-A-E04.dcc  1072/1043  Thymus    B220
## DSP-1001660007393-A-E05.dcc  1072/1043  Thymus    B220
## DSP-1001660007393-A-E06.dcc  1072/1043  Thymus     CD3
## DSP-1001660007393-A-E07.dcc  1072/1043  Thymus   PanCK
## DSP-1001660007393-A-E08.dcc  1072/1043  Thymus     CD3
## DSP-1001660007393-A-E09.dcc  1072/1043  Thymus   PanCK
## DSP-1001660007393-A-E10.dcc  1072/1043  Thymus     CD3
## DSP-1001660007393-A-E11.dcc  1072/1043  Thymus   PanCK
## DSP-1001660007393-A-E12.dcc  1042/1044 Thymoma   PanCK
## DSP-1001660007393-A-F01.dcc  1042/1044 Thymoma     CD3
## DSP-1001660007393-A-F02.dcc  1042/1044 Thymoma   PanCK
## DSP-1001660007393-A-F03.dcc  1042/1044 Thymoma     CD3
## DSP-1001660007393-A-F04.dcc  1042/1044 Thymoma   PanCK
## DSP-1001660007393-A-F05.dcc  1042/1044 Thymoma     CD3
## DSP-1001660007393-A-F06.dcc  1042/1044 Thymoma   PanCK
## DSP-1001660007393-A-F07.dcc  1042/1044 Thymoma    B220
## DSP-1001660007393-A-F08.dcc  1042/1044 Thymoma    B220
## DSP-1001660007393-A-F09.dcc  1042/1044 Thymoma    B220
## DSP-1001660007393-A-F10.dcc  1042/1044 Thymoma    B220
## DSP-1001660007393-A-F11.dcc  1042/1044 Thymoma    B220
## DSP-1001660007393-A-F12.dcc  1042/1044 Thymoma    B220
## DSP-1001660007393-A-G01.dcc  1042/1044 Thymoma     CD3
## DSP-1001660007393-A-G02.dcc  1042/1044 Thymoma   PanCK
## DSP-1001660007393-A-G03.dcc  1042/1044 Thymoma     CD3
## DSP-1001660007393-A-G04.dcc  1042/1044 Thymoma   PanCK
## DSP-1001660007393-A-G05.dcc  1042/1044 Thymoma     CD3
## DSP-1001660007393-A-G06.dcc  1042/1044 Thymoma   PanCK
## DSP-1001660007393-A-G07.dcc  1082/1157 Thymoma    B220
## DSP-1001660007393-A-G08.dcc  1082/1157 Thymoma    B220
## DSP-1001660007393-A-G09.dcc  1082/1157 Thymoma    B220
## DSP-1001660007393-A-G10.dcc  1082/1157 Thymoma   PanCK
## DSP-1001660007393-A-G11.dcc  1082/1157 Thymoma     CD3
## DSP-1001660007393-A-G12.dcc  1082/1157 Thymoma   PanCK
## DSP-1001660007393-A-H01.dcc  1082/1157 Thymoma     CD3
## DSP-1001660007393-A-H02.dcc  1082/1157 Thymoma   PanCK
## DSP-1001660007393-A-H03.dcc  1082/1157 Thymoma     CD3
## DSP-1001660007393-A-H04.dcc  1082/1157 Thymoma    B220
## DSP-1001660007393-A-H05.dcc  1082/1157 Thymoma    B220
## DSP-1001660007393-A-H06.dcc  1082/1157 Thymoma   PanCK
## DSP-1001660007393-A-H07.dcc  1082/1157 Thymoma     CD3
## DSP-1001660007393-A-H08.dcc  1082/1157 Thymoma   PanCK
## DSP-1001660007393-A-H09.dcc  1082/1157 Thymoma     CD3
## DSP-1001660007393-A-H10.dcc  1082/1157 Thymoma   PanCK
## DSP-1001660007393-A-H11.dcc  1082/1157 Thymoma     CD3
## DSP-1001660007393-A-H12.dcc  1082/1157 Thymoma    B220

2. QC Preprocessing:

qc.output <-  qcProc(object = sdesign.list$object,
                        min.segment.reads = 1000,
                        percent.trimmed = 80,
                        percent.stitched = 80,
                        percent.aligned = 80,
                        percent.saturation = 50,
                        min.negative.count = 1,  
                        max.ntc.count = 1000,     
                        min.nuclei = 200,         
                        min.area = 16000,
                        print.plots = TRUE)

## 
## 
## Table: Summary for the NTC values
## 
## |NTC Count | # of Segments|
## |:---------|-------------:|
## |146       |            95|
## 
## 
## Table: QC Summary for each Segment
## 
## |              | Pass| Warning|
## |:-------------|----:|-------:|
## |LowReads      |   95|       0|
## |LowTrimmed    |   95|       0|
## |LowStitched   |   95|       0|
## |LowAligned    |   95|       0|
## |LowSaturation |   95|       0|
## |LowNegatives  |   95|       0|
## |HighNTC       |   95|       0|
## |LowNuclei     |   92|       3|
## |LowArea       |   90|       5|
## |TOTAL FLAGS   |   90|       5|
## 
## 
## Table: Summary for Segment QC Removal
## 
## |         | # Before Removal| # After Removal|
## |:--------|----------------:|---------------:|
## |Features |            20175|           20175|
## |Samples  |               95|              90|
## 
## 
## Table: Summary for Probe QC Calls (Grubb's Outlier Test)
## 
## | Passed| Global| Local|
## |------:|------:|-----:|
## |  20167|      0|     8|
## 
## 
## Table: Summary for Probe QC Removal
## 
## |         | # Before Collapsing| # After Collapsing|
## |:--------|-------------------:|------------------:|
## |Features |               20175|              20175|
## |Samples  |                  90|                 90|
## 
## 
## Table: Summary for Gene-level Counts
## 
## |         | # Before Collapsing| # After Collapsing|
## |:--------|-------------------:|------------------:|
## |Features |               20175|              19963|
## |Samples  |                  90|                 90|
    print(qc.output$segments.qc)
## NULL
  create.rds <- TRUE
  if(create.rds) {
    qc.mouse.thymus <- qc.output$object
    saveRDS(qc.mouse.thymus, file = "tests/testthat/fixtures/Mouse_Thymus/qcMouseThymus.RDS")
  }

3. Filtering:

    goi <- c("Plb1", "Ccr7", "Oas2", "Oas1a", "Oas1b", "Rhbdl2", "Dlst", "Naa15", "Rab11a", "Desi1", "Tfdp1", "Foxn1")
    
    filtering.output <- filtering(object = qc.output$object,
                            loq.cutoff = 2, 
                            loq.min = 2, 
                            cut.segment = .05, 
                            goi = goi)
    
    print(filtering.output$`stacked.bar.plot`)

    print(filtering.output$`tab`)
## 
## 
## |       | Thymoma| Thymus|
## |:------|-------:|------:|
## |<1%    |       0|      0|
## |1-5%   |       0|      0|
## |5-10%  |       0|      3|
## |10-15% |       0|      8|
## |>15%   |      37|     42|
    print(filtering.output$`sankey.plot`)

    print(filtering.output$`genes.detected.plot`)

  create.rds <- TRUE
  if(create.rds) {
    filtering.mouse.thymus <- filtering.output$object
    saveRDS(filtering.mouse.thymus, file = "tests/testthat/fixtures/Mouse_Thymus/filteringMouseThymus.RDS")
  }

4. Normalization:

    q3.normalization.output <- geomxNorm(
                                  object = filtering.output$object, 
                                  norm = "q3")
## Using Segment, Annotation as id variables
## No id variables; using all as measure variables
## No id variables; using all as measure variables
    print(q3.normalization.output$multi.plot)

    print(q3.normalization.output$boxplot.raw)

    print(q3.normalization.output$boxplot.norm)

    neg.normalization.output <- geomxNorm(
                                  object = filtering.output$object, 
                                  norm = "neg")
## Using Segment, Annotation as id variables
## No id variables; using all as measure variables
## No id variables; using all as measure variables
    print(neg.normalization.output$multi.plot)

    print(neg.normalization.output$boxplot.raw)

    print(neg.normalization.output$boxplot.norm)

    create.rds <- TRUE
    if(create.rds) {
      q3.normalization.mouse.thymus <- q3.normalization.output$object
      saveRDS(q3.normalization.mouse.thymus, file = "tests/testthat/fixtures/Mouse_Thymus/q3normalizationMouseThymus.RDS")
      neg.normalization.mouse.thymus <- neg.normalization.output$object
      saveRDS(neg.normalization.mouse.thymus, file = "tests/testthat/fixtures/Mouse_Thymus/negnormalizationMouseThymus.RDS")
    }

5. Unsupervised Analysis:

    #Test Unsupervised Analysis:
    unsupervised.output <- dimReduct(object = q3.normalization.output$object,
                        point.size = 3,
                        point.alpha = 1,
                        color.variable1 = "region",
                        shape.variable = "class"
    )
## using q_norm in the dimensional reductions
## adding in the phenoData PCA, tSNE, and UMAP coordinates
    print(unsupervised.output$plot$PCA)

    print(unsupervised.output$plot$tSNE)

    print(unsupervised.output$plot$UMAP)

6. Clustering high CV Genes and Heatmap:

    heatmap.output <- heatMap(object = unsupervised.output$object, 
                        ngenes = 200, 
                        scale.by.row.or.col = "row", 
                        show.rownames = FALSE, 
                        show.colnames = FALSE, 
                        clustering.method = "average", 
                        cluster.rows = TRUE, 
                        cluster.cols = TRUE,
                        clustering.distance.rows = "correlation", 
                        clustering.distance.cols = "correlation", 
                        annotation.row = NA, 
                        annotation.col = c("class", "segment", "region"), 
                        breaks.by.values = seq(-3, 3, 0.05), 
                        heatmap.color = colorRampPalette(c("blue", "white", "red"))(120), 
                        norm.method = "quant")
## Warning: It not suggested to both set `scale` and `breaks`. It makes the
## function confused.
    print(heatmap.output$plot)

7. Differential Expression Analysis:

    goi <- c("Plb1", "Ccr7", "Oas2", "Oas1a", "Oas1b", "Rhbdl2", "Dlst", 
             "Naa15", "Rab11a", "Desi1", "Tfdp1", "Foxn1")
    
    object <- q3.normalization.output$object
    object <- object[goi,]
    Gene <- Subset <- NULL
    
    #First analysis:
    reslist.1 <- diffExpr(object = object, 
                          analysis.type = "Within Groups", 
                          region.col = "region", 
                          regions = c("Cortical", "Medullar"), 
                          group.col = "class", 
                          groups = c("Thymus"), 
                          n.cores = 4)
## At least one of the regions within the Region Column was not selected
##             and is excluded: Unspecified, Tumor
## Running Within Group Analysis between Regions
## Number of regions in group Thymus: 2
    grid.draw(reslist.1$sample_table)
    grid.newpage()
    grid.draw(reslist.1$summary_table)
    
    lfc_col1 <- colnames(reslist.1$result)[grepl("logFC",colnames(reslist.1$result))]
    pval_col1 <- colnames(reslist.1$result)[grepl("_pval",colnames(reslist.1$result))]
    
    lfc.1 <- reslist.1$result %>% 
              dplyr::filter(Gene == "Ccr7" & Subset == "Thymus") %>% 
              select(all_of(lfc_col1)) %>% 
              as.numeric()
    pval.1 <- reslist.1$result %>% 
              dplyr::filter(Gene == "Ccr7" & Subset == "Thymus") %>% 
              select(all_of(pval_col1)) %>% 
              as.numeric()
    
    cat(paste0("\n\nvalue of Ccr7 Fold Change is:", lfc.1))
## 
## 
## value of Ccr7 Fold Change is:-1.5874
    cat("expected value is -1.645")
## expected value is -1.645
    cat(paste0("\nvalue of Ccr7 pval is:",pval.1))
## 
## value of Ccr7 pval is:7.39e-06
    cat("expected value is 0.0274")
## expected value is 0.0274
    #Second analysis:
    reslist.2 <- diffExpr(object = object, 
                          analysis.type = "Between Groups", 
                          region.col = "segment", 
                          regions = c("PanCK"), 
                          group.col = "region", 
                          groups = c("Tumor", "Medullar"), 
                          n.cores = 1)
## At least one of the regions within the Region Column was not selected
##             and is excluded: CD3, B220
## Running Between Group Analysis for Regions
## Number of groups in region PanCK: 2
    grid.draw(reslist.2$sample_table)
    grid.newpage()
    grid.draw(reslist.2$summary_table)
    
    lfc_col2 <- colnames(reslist.2$result)[grepl("logFC",colnames(reslist.2$result))]
    pval_col2 <- colnames(reslist.2$result)[grepl("_pval",colnames(reslist.2$result))]
    
    lfc.2 <- reslist.2$result %>% 
              dplyr::filter(Gene == "Ccr7" & Subset == "PanCK") %>% 
              select(all_of(lfc_col2)) %>% 
              as.numeric()
    pval.2 <- reslist.2$result %>% 
              dplyr::filter(Gene == "Ccr7" & Subset == "PanCK") %>% 
              select(all_of(pval_col2)) %>% 
              as.numeric()
    
    cat(paste0("\n\nvalue of Ccr7 Fold Change is: ", lfc.2))
## 
## 
## value of Ccr7 Fold Change is: -1.64
    cat("expected value is -1.89")
## expected value is -1.89
    cat(paste0("\nvalue of Ccr7 pval is: ",pval.2))
## 
## value of Ccr7 pval is: 7.11e-09
    cat("expected value is 4.97e-12")
## expected value is 4.97e-12

8. Volcano Plot

#This part is run on NIDAP.

9. Violin Plot

    genes <- c("Plb1", "Ccr7", "Oas2", "Oas1a", "Oas1b", "Rhbdl2", "Dlst", 
               "Naa15", "Rab11a", "Desi1", "Tfdp1", "Foxn1")
    
    violin.plot.test <- violinPlot(object = q3.normalization.output$object, 
                                        expr.type = "q_norm", 
                                        genes = genes,
                                        group = "region",
                                        facet.by = "segment")
## [1] " not found and will not be displayed"
    grid.arrange(violin.plot.test)

10. Spatial Deconvolution:

    ref.mtx = read.csv(test_path("fixtures", "sample_spatial_deconv_mtx.csv"), 
                       row.names=1, check.names=FALSE)
    rownames(ref.mtx) = sample(rownames(q3.normalization.output$object), size = 1500, replace = FALSE)
    ref.annot = read.csv(test_path("fixtures", "ref_annot.csv"))
    
    spatial.output <- spatialDeconvolution(object = q3.normalization.output$object, 
                                           expr.type = "q_norm", 
                                           ref.mtx = ref.mtx, 
                                           ref.annot = ref.annot, 
                                           prof.mtx = NULL, 
                                           use.custom.prof.mtx = TRUE,
                                           cell.id.col = "CellID", 
                                           celltype.col = "LabeledCellType", 
                                           group.by = "segment")
## Warning in create_profile_matrix(mtx = ref.mtx, cellAnnots = ref.annot, : not
## all cellNameCol names are in count matrix; 5311 cells are missing
## [1] "Creating Atlas"
## [1] "1 / 21 : cTEC"
## [1] "2 / 21 : cTEC(cycling)"
## [1] "3 / 21 : mTEC_I"
## [1] "4 / 21 : mTEC_II"
## [1] "5 / 21 : TEC_Cldn10"
## [1] "6 / 21 : Epi(lung)"
## [1] "7 / 21 : muscle"
## [1] "8 / 21 : Fb_Postn"
## [1] "9 / 21 : mTEC_III"
## [1] "10 / 21 : Immune"
## [1] "11 / 21 : TEC(neuro)_like_1"
## [1] "12 / 21 : mTEC_IV(tuft)"
## [1] "13 / 21 : Fb_Aldh1a2"
## [1] "14 / 21 : Fb_Pi16"
## [1] "15 / 21 : Endo"
## [1] "16 / 21 : Mac"
## [1] "17 / 21 : TEC(neuro)_like_2"
## [1] "18 / 21 : Epi_Gcm2"
## [1] "19 / 21 : VSMC"
## [1] "20 / 21 : Epi_PAX8"
## [1] "21 / 21 : Ery"
## Using celltype as id variables
## Warning in xtfrm.data.frame(x): cannot xtfrm data frames
    print(spatial.output$figures)
## $abundance.heatmap

## 
## $cell.profile.heatmap

## 
## $composition.barplot

    print("Spatial Deconvolution Done")
## [1] "Spatial Deconvolution Done"